package com.example.myapplication.fragment;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.example.myapplication.R;

public class f4second extends Fragment {
    View view;
    Context context;
    private TextView lufei;
    private RadioGroup radioGroup;
    private RadioButton rbShitou;
    private RadioButton rbQiandao;
    private RadioButton rbBu;
    private Button button;
    String game1;
    caa2 caa2;
    public f4second() {
        // Required empty public constructor
    }
    public  static f4second getInstance(String game){
        f4second f4second=new f4second();
        Bundle bundle=new Bundle();
        bundle.putString("game",game);
        f4second.setArguments(bundle);
        return f4second;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        view = inflater.inflate(R.layout.fragment_f4second, container, false);
        context=getContext();
        initView();
        Bundle bundle=getArguments();
        game1=bundle.getString("game");
        getString();
        return view;
    }
    /*
      跳转传值
       */
    public void getString(){

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RadioButton radioButton = (RadioButton) view.findViewById(radioGroup.getCheckedRadioButtonId());
                String game2=radioButton.getText().toString();
                if(game1.equals("石头")&&game2.equals("剪刀")){
                    caa2.change2("路飞赢了");
                }
                if(game1.equals("石头")&&game2.equals("石头")){
                    caa2.change2("平局");
                }
                if(game1.equals("石头")&&game2.equals("布")){
                    caa2.change2("女帝赢了");
                }
                if(game1.equals("剪刀")&&game2.equals("石头")){
                    caa2.change2("女帝赢了");
                }
                if(game1.equals("剪刀")&&game2.equals("剪刀")){
                    caa2.change2("平局");
                }
                if(game1.equals("剪刀")&&game2.equals("布")){
                    caa2.change2("路飞赢了");
                }
                if(game1.equals("布")&&game2.equals("石头")){
                    caa2.change2("路飞赢了");
                }
                if(game1.equals("布")&&game2.equals("剪刀")){
                    caa2.change2("女帝赢了");
                }
                if(game1.equals("布")&&game2.equals("布")){
                    caa2.change2("平局");
                }
            }
        });
    }
    /*
    初始化控件
     */
    private void initView() {
        lufei = (TextView) view.findViewById(R.id.lufei);
        radioGroup = (RadioGroup) view.findViewById(R.id.radioGroup);
        rbShitou = (RadioButton) view.findViewById(R.id.rb_shitou);
        rbQiandao = (RadioButton) view.findViewById(R.id.rb_qiandao);
        rbBu = (RadioButton) view.findViewById(R.id.rb_bu);
        button = (Button) view.findViewById(R.id.button);
    }
    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        caa2 = (caa2) context;
    }
    public interface caa2 {
        public void change2(String game);
    }
}
